Action hook 'comment_{$old_status}_to_{$new_status}'

in WP Core File wp-includes/comment.php at line 1869

View Source

comment_{$old_status}_to_{$new_status}

Action Hook
Description
Fires when the comment status is in transition from one specific status to another. The dynamic portions of the hook name, `$old_status`, and `$new_status`, refer to the old and new comment statuses, respectively. Possible hook names include: - `comment_unapproved_to_approved` - `comment_spam_to_approved` - `comment_approved_to_unapproved` - `comment_spam_to_unapproved` - `comment_unapproved_to_spam` - `comment_approved_to_spam`

Hook Information

File Location wp-includes/comment.php View on GitHub
Hook Type Action
Line Number 1869

Hook Parameters

Type Name Description
WP_Comment $comment Comment object.

Usage Examples

Basic Usage
<?php
// Hook into comment_{$old_status}_to_{$new_status}
add_action('comment_{$old_status}_to_{$new_status}', 'my_custom_function', 10, 1);

function my_custom_function($comment) {
    // Your custom code here
}

Source Code Context

wp-includes/comment.php:1869 - How this hook is used in WordPress core
<?php
1864  		 *
1865  		 * @since 2.7.0
1866  		 *
1867  		 * @param WP_Comment $comment Comment object.
1868  		 */
1869  		do_action( "comment_{$old_status}_to_{$new_status}", $comment );
1870  	}
1871  	/**
1872  	 * Fires when the status of a specific comment type is in transition.
1873  	 *
1874  	 * The dynamic portions of the hook name, `$new_status`, and `$comment->comment_type`,

PHP Documentation

<?php
/**
		 * Fires when the comment status is in transition from one specific status to another.
		 *
		 * The dynamic portions of the hook name, `$old_status`, and `$new_status`,
		 * refer to the old and new comment statuses, respectively.
		 *
		 * Possible hook names include:
		 *
		 *  - `comment_unapproved_to_approved`
		 *  - `comment_spam_to_approved`
		 *  - `comment_approved_to_unapproved`
		 *  - `comment_spam_to_unapproved`
		 *  - `comment_unapproved_to_spam`
		 *  - `comment_approved_to_spam`
		 *
		 * @since 2.7.0
		 *
		 * @param WP_Comment $comment Comment object.
		 */
Quick Info
  • Hook Type: Action
  • Parameters: 1
  • File: wp-includes/comment.php
Related Hooks

Related hooks will be displayed here in future updates.